Skip to content

opentelemetry-api: remove env carrier environment snapshot caching#5366

Open
pellared wants to merge 2 commits into
open-telemetry:mainfrom
pellared:env-car-spec
Open

opentelemetry-api: remove env carrier environment snapshot caching#5366
pellared wants to merge 2 commits into
open-telemetry:mainfrom
pellared:env-car-spec

Conversation

@pellared

@pellared pellared commented Jun 29, 2026

Copy link
Copy Markdown
Member

Follows open-telemetry/opentelemetry-specification#5179

Update EnvironmentGetter to read from the supplied carrier mapping at lookup time, while still normalizing requested keys and returning only already-normalized keys from keys().

There is a performance motivation for removing the snapshot. The previous implementation scanned and copied the full process environment when EnvironmentGetter was constructed, even though extraction normally reads only a small, fixed set of propagation keys such as TRACEPARENT, TRACESTATE, and BAGGAGE. Reading directly from the supplied carrier avoids that upfront O(n) environment scan and keeps work proportional to the keys actually requested by the propagator

@pellared pellared requested a review from a team as a code owner June 29, 2026 08:10
@pellared

pellared commented Jun 29, 2026

Copy link
Copy Markdown
Member Author

CC @xrmx @lzchen @adrielp

@pellared pellared marked this pull request as draft June 30, 2026 14:39
@pellared pellared marked this pull request as ready for review June 30, 2026 14:49
Copilot AI review requested due to automatic review settings June 30, 2026 14:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the opentelemetry-api environment carrier so EnvironmentGetter no longer snapshots os.environ at construction time, and instead reads directly from the provided carrier mapping at lookup time (aligning with the linked spec change and avoiding an upfront full-environment scan).

Changes:

  • Remove EnvironmentGetter’s initialization-time snapshot and read values from the supplied carrier in get().
  • Update keys() to return only already-normalized keys from the supplied carrier.
  • Adjust env-carrier propagator tests to pass os.environ (or a dict carrier) into extract() / get() accordingly, and add a changelog entry.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
opentelemetry-api/src/opentelemetry/propagators/_envcarrier.py Removes env snapshot caching; EnvironmentGetter now reads from the passed carrier and filters normalized keys from it.
opentelemetry-api/tests/propagators/test__envcarrier.py Updates tests to pass the carrier mapping (including os.environ) to match the new getter behavior and adds coverage for non-snapshot behavior.
.changelog/5366.changed Records the behavioral/performance change in the changelog system.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread opentelemetry-api/src/opentelemetry/propagators/_envcarrier.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants